package ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.web.base.domain.view.ViewResultDTO;
import ${projectDefinitionDO.basePackage}.sdk.dto.AccountInfoDTO;

<#if projectDefinitionDO.parentProjectDefinitionDO.javaVersion != '1.8' && projectDefinitionDO.parentProjectDefinitionDO.javaVersion != '8'>
import jakarta.annotation.Resource;
<#else>
import javax.annotation.Resource;
</#if>
import java.util.Map;
import java.util.HashMap;
import java.util.Date;

//import ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.config.Config1;
@Controller("${projectDefinitionDO.serverProjectDefinitionDO.serverProjectClassNameForVariableName}HelloWorld")
@RequestMapping("${projectDefinitionDO.serverProjectDefinitionDO.serverProjectClassNameForVariableName}HelloWorld")
public class HelloWorldController {

    private static final Logger logger = LogManager.getLogger(HelloWorldController.class);

    @RequestMapping("sayHelloWorld")
    @ResponseBody
    public String sayHelloWorld(String name) {
        logger.info("name is : " + name);
        System.out.println("hello " + name);
        return "welcome to world, " + name;
    }


    @RequestMapping("sayHelloWorld2")
    @ResponseBody
    public AccountInfoDTO sayHelloWorld2(String name) {
        AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
        accountInfoDTO.setUserName(name);
        accountInfoDTO.setUpdateTime(new Date());
        return accountInfoDTO;
    }

    @RequestMapping("sayHelloWorld3")
    @ResponseBody
    public ViewResultDTO<AccountInfoDTO> sayHelloWorld3(AccountInfoDTO accountInfoDTO) {
        ViewResultDTO<AccountInfoDTO> viewResultDTO = new ViewResultDTO<>();
        if (accountInfoDTO == null) {
            accountInfoDTO = new AccountInfoDTO();
            accountInfoDTO.setUserName("helloServer");
            accountInfoDTO.setUpdateTime(new Date());
        }
        viewResultDTO.setData(accountInfoDTO);
        return viewResultDTO;
    }

//    @Resource
//    private Config1 config1;
//
//    @RequestMapping("getConfigInfo")
//    @ResponseBody
//    public String getConfigInfo() {
//       Gson gson = new Gson();
//       Map map = new HashMap();
//       map.put("a1", config1.getA1());
//       map.put("a2", config1.getA2());
//       map.put("a3", config1.getA3());
//       map.put("UserConfig", config1.getUserConfig());
//       return gson.toJson(map);
//     }
}
